//
//  AddViewController.m
//  通讯录-02
//
//  Created by 伍银荣 on 2021/6/29.
//  Copyright © 2021 com.example. All rights reserved.
//

#import "AddViewController.h"

@interface AddViewController ()
@property (strong, nonatomic) IBOutlet UITextField *nameTF;
@property (strong, nonatomic) IBOutlet UITextField *numberTF;
@property (strong, nonatomic) IBOutlet UIButton *addBtn;


@end

@implementation AddViewController


- (IBAction)addBtnClicked:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(addViewController:andNameText:andNumberText:)]) {
        [self.delegate addViewController:self andNameText:self.nameTF.text andNumberText:self.numberTF.text];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.nameTF becomeFirstResponder];
    [self.nameTF addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged];
    [self.numberTF addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged];
    
}

- (void)textChanged {
    if (self.nameTF.text.length > 0 && self.numberTF.text.length > 0) {
        self.addBtn.enabled = YES;
    }
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
